home *** CD-ROM | disk | FTP | other *** search
/ Aminet 23 / Aminet 23 (1998)(GTI - Schatztruhe)[!][Feb 1998].iso / Aminet / util / cli / DevEx10a.lha / DevEx.c next >
Encoding:
C/C++ Source or Header  |  1997-12-21  |  1.6 KB  |  84 lines

  1. #include <exec/execbase.h>
  2. #include <dos/dos.h>
  3. #include <proto/exec.h>
  4. #include <proto/dos.h>
  5.  
  6. #include <string.h>
  7. struct ExecBase *SysBase;
  8. struct DosLibrary *DOSBase;
  9.  
  10. struct RDArgs *RDArgs;
  11.  
  12. struct {
  13.     BYTE *Device;
  14.     LONG *Unit;
  15. } Args;
  16.  
  17. struct IOStdReq *IOReq;
  18. struct MsgPort *ReplyPort;
  19. LONG Unit;
  20. LONG Warn=20;
  21.  
  22. VOID cleanup(BYTE str[]);
  23.  
  24. LONG __saveds main(VOID)
  25. {
  26.     SysBase=*(struct ExecBase **)4;
  27.  
  28.     if ((DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",0))==NULL)
  29.         return 100;
  30.  
  31.     if (DOSBase->dl_lib.lib_Version<36)
  32.     {
  33.         cleanup("You need Kickstart 2.0 or better.\n");
  34.         return 20;
  35.     }
  36.  
  37.     if ((RDArgs=ReadArgs("DEVICE/A,UNIT/N/O",(LONG *)&Args,NULL))==NULL)
  38.     {
  39.         cleanup("Invalid arguments.\n");
  40.         return 20;
  41.     }
  42.  
  43.     if (Args.Unit==NULL)
  44.         Args.Unit=&Unit;
  45.  
  46.     if ((ReplyPort=(struct MsgPort *)CreateMsgPort())==NULL)
  47.     {
  48.         cleanup("Cannot create port.\n");
  49.         return 20;
  50.     }
  51.  
  52.     if ((IOReq=(struct IOStdReq *)
  53.         CreateIORequest(ReplyPort,sizeof(struct IOStdReq)))==NULL)
  54.     {
  55.         cleanup("Cannot create IO request.\n");
  56.         return 20;
  57.     }
  58.  
  59.     Warn=(OpenDevice(Args.Device,*Args.Unit,(struct IORequest *)IOReq,0) ? 5:0);
  60.  
  61.     Printf("%s, unit %ld %s.\n",Args.Device,*Args.Unit,
  62.         Warn ? "doesn't exist":"exists");
  63.  
  64.     cleanup(NULL);
  65.     return Warn;
  66. }
  67.  
  68.  
  69. VOID cleanup(BYTE str[])
  70. {
  71.     if (str!=NULL)
  72.         Write(Output(),str,strlen(str));
  73.     if (ReplyPort!=NULL)
  74.         DeleteMsgPort(ReplyPort);
  75.     if (!Warn)
  76.         CloseDevice((struct IORequest *)IOReq);
  77.     if (IOReq!=NULL)
  78.         DeleteIORequest((struct IORequest *)IOReq);
  79.     if (RDArgs!=NULL)
  80.         FreeArgs(RDArgs);
  81.     if (DOSBase!=NULL)
  82.         CloseLibrary((struct Library *)DOSBase);
  83. }
  84.